import 'package:yuellyfactory/views/dto/PriceMaterial.dart';
import 'package:yuellyfactory/views/dto/PriceParm.dart';
import 'package:yuellyfactory/views/dto/PriceSerial.dart';

class PricePart{

  String path="";
  String id="";
  String modelId="";
  String name="";
  String parentId="";
   String configId="";
   String spec="";
   String priceConfig="";
   String supplierId="";
  String code="";
  String rule="";
  String materialRule="";
  double count=0;
  String createTime="";
  String updateTime="";
  String serialId="";
  String serial="";

  String typeId="";

  String area1="";
  String area2="";
  String weight1="";
  String weight2="";



  double dPrice=0;
  double mPrice=0;
  String tax="0";
  String grossMargin="0";
  String profitMargin="0";
  String retailRatio="0";

  String data="";
  String remark="";

  List parmList=[];
  List childParmList=[];
  List materialList=[];
  String type="";
  List priceModels=[];
  List priceParts=[];
  List serialList=[];
  List childMaterialList=[];

  List remarkList=[];
  List serialParmList=[];
  List serialDataList=[];
  List brandParmList=[];
  List brandDataList=[];
  List partParmList=[];

  int showInput=0;

  String level="";

  PriceSerial priceSerial=PriceSerial();

  double price=0;
 
  double totalPrice=0;
  //出厂价
  double exFactoryPrice=0;
  //代理商价
  double agentPrice=0;
  //终端价
  double retailPrice=0;

  bool isShow=false;

  String remarkData="";
  String dataDetail="";


  String discount="";
  String parmData="";

  String config="";
  String selectConfig="";


  String s1="";
  String s2="";
  String h1="";
  String h2="";
  String e1="";
  String e2="";
  String w1="";
  String w2="";
  String d1="";
  String d2="";
  String c1="";
  String c2="";



  bool select=false;

  PricePart();
  PricePart.fromName(var nameStr){
    name=nameStr;
    id="";
    modelId="";
    name="";
    parentId="";
    configId="";
    spec="";
    code="";
    rule="";
    materialRule="";
    type="";
    count=0;
    serialId="";
    serial="";


    updateTime="";
    createTime="";
  }

  PricePart.fromJson(Map<String,dynamic> json){
    id=json["id"]??"";
    modelId=json["modelId"]??"";
    name=json["name"]??"";
    parentId=json["parentId"]??"";
    configId=json["configId"]??"";
    spec=json["spec"]??"";
    code=json["code"]??"";
    rule=json["rule"]??"";

    priceConfig=json["priceConfig"]??"";
    supplierId=json["supplierId"]??"";

    area1=json["area1"]??"";
    area2=json["area2"]??"";
    weight1=json["weight1"]??"";
    weight2=json["weight2"]??"";

    materialRule=json["materialRule"]??"";
    type=json["type"]??"";
    typeId=json["typeId"]??"";
    dPrice=json["dprice"]??0.0;
    mPrice=json["mPrice"]??0.0;
    showInput=json["showInput"]??0;
    tax=json["tax"]??"0";
    grossMargin=json["grossMargin"]??"0";
    profitMargin=json["profitMargin"]??"0";
    retailRatio=json["retailRatio"]??"0";
    level=json["level"]==0?"":json["level"].toString();
    count=(json["count"] as num?)?.toDouble() ?? 0.0;
    serialId=json["serialId"]??"";
    serial=json["serial"]??"";
    data=json["data"]??"";
    remark=json["remark"]??"";
    config=json["config"]??"";
    selectConfig=json["selectConfig"]??"";
    updateTime=json["updateTime"]??"";
    createTime=json["createTime"]??"";
    remarkData=json["remarkData"]??"";
    dataDetail=json["dataDetail"]??"";
    discount=json["discount"]??"";
    parmData=json["parmData"]??"";

    s1=json["s1"].toString()??"";
    s2=json["s2"].toString()??"";
    h1=json["h1"].toString()??"";
    h2=json["h2"].toString()??"";
    e1=json["e1"].toString()??"";
    e2=json["e2"].toString()??"";
    w1=json["w1"].toString()??"";
    w2=json["w2"].toString()??"";
    d1=json["d1"].toString()??"";
    d2=json["d2"].toString()??"";
    c1=json["c1"].toString()??"";
    c2=json["c2"].toString()??"";


    var materialJson=json["materialList"];
    var parmJson=json["parmList"];
    var childParmJson=json["childParmList"];
    var partJson=json["priceParts"];
    var modelJson=json["priceModels"];
    var serialJson=json["serialList"];

    var serialModel=json["pricePartSerial"];

    var remarkListJson=json["remarkList"];

    var serialParmListJson=json["serialParmList"];
    var serialDataListJson=json["serialDataList"];
    var brandParmListJson=json["brandParmList"];
    var brandDataListJson=json["brandDataList"];

    var partParmListJson=json["partParmList"];

    if(remarkListJson!=null){
      remarkList=[];
      for(var item in remarkListJson){
        PriceParm parm=PriceParm.fromJson(item);
        remarkList.add(parm);
      }
    }
    if(serialParmListJson!=null){
      serialParmList=[];
      for(var item in serialParmListJson){
        PriceParm parm=PriceParm.fromJson(item);
        serialParmList.add(parm);
      }
    }
    if(serialDataListJson!=null){
      serialDataList=[];
      for(var item in serialDataListJson){
        PriceParm parm=PriceParm.fromJson(item);
        serialDataList.add(parm);
      }
    }

    if(brandParmListJson!=null){
      brandParmList=[];
      for(var item in brandParmListJson){
        PriceParm parm=PriceParm.fromJson(item);
        brandParmList.add(parm);
      }
    }

    if(brandDataListJson!=null){
      brandDataList=[];
      for(var item in brandDataListJson){
        PriceParm parm=PriceParm.fromJson(item);
        brandDataList.add(parm);
      }
    }


    if(partParmListJson!=null){
      partParmList=[];
      for(var item in partParmListJson){
        PriceParm parm=PriceParm.fromJson(item);
        partParmList.add(parm);
      }
    }


    if(serialModel!=null){
      priceSerial=PriceSerial.fromJson(serialModel);
    }

    var childMaterialJson=json["childMaterialList"];

    if(childMaterialJson!=null){
      childMaterialList=[];
      for(var item in childMaterialJson){
        PriceMaterial material=PriceMaterial.fromJson(item);
        childMaterialList.add(material);
      }
    }



    if(serialJson!=null){
      for(var item in serialJson){
        PriceSerial serial=PriceSerial.fromJson(item);
        serialList.add(serial);
      }
    }

    if(materialJson!=null){
      materialList=[];
      for(var item in materialJson){
        PricePart part=PricePart.fromJson(item);
        materialList.add(part);
      }
    }
    if(partJson!=null){
      priceParts=[];
      for(var item in partJson){
        PricePart part=PricePart.fromJson(item);
        priceParts.add(part);
      }
    }
   if(parmJson!=null){
     parmList=[];
     for(var item in parmJson){
       PriceParm parm=PriceParm.fromJson(item);
       parmList.add(parm);
     }
   }

    if(childParmJson!=null){
      childParmList=[];
      for(var item in childParmJson){
        PriceParm parm=PriceParm.fromJson(item);
        childParmList.add(parm);
      }
    }
   if(modelJson!=null){
     for(var item in modelJson){
       PricePart model=PricePart.fromJson(item);
       //再判断第三级
       var thirdmodelJson=item["priceModels"];
       if(thirdmodelJson!=null){
         for(var item in thirdmodelJson){
           PricePart part=PricePart.fromJson(item);
           var fourpriceParts=item["priceParts"];
           if(fourpriceParts!=null){
             for(var four in fourpriceParts){
               PricePart fourpart=PricePart.fromJson(four);
               fourpart.type="part";
               part.materialList.add(fourpart);
             }
           }
           model.materialList.add(part);
         }
       }
       priceModels.add(model);
     }
   }

  }

}